<template>
  <div class="index">
    <el-container>
      <el-header height="68px">
        <m-header></m-header>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <m-aside></m-aside>
        </el-aside>
        <el-main>
          <div class="audit">
            <div class="title">发送历史</div>
            <div class="search">
              <div class="item">
                <label>发送时间：</label>
                <el-date-picker v-model="time" type="date" @change="getTime" placeholder="选择日期"></el-date-picker>
              </div>
              <div class="item">
                <label>发送类型：</label>
                <el-select v-model="value2" placeholder="请选择" @change="change2">
                  <el-option v-for="item in options2" :key="item.value" :value="item.value"></el-option>
                </el-select>
              </div>
              <div class="item">
                <label>发送状态</label>
                <el-select v-model="value1" placeholder="请选择" @change="change1">
                  <el-option v-for="item in options1" :key="item.value" :value="item.value"></el-option>
                </el-select>
              </div>
              <div class="item">
                <label>手机号码:</label>
                <el-input v-model="iphone" placeholder="手机号码"></el-input>
              </div>
              <el-button
                type="primary"
                class="searchs"
                size="small"
                icon="el-icon-search"
                @click="search"
              >搜索</el-button>
            </div>

            <div class="table">
              <el-table
                :data="tableData"
                border
                :cell-style="{'text-align':'center'}"
                :header-cell-style="{
          'background-color': '#f5f5f5',
          'color':'#666',
          'text-align':'center'
        }"
                style="width: 100%"
              >
                <el-table-column prop="phoneNumber" label="手机号码" width="180"></el-table-column>
                <el-table-column prop="sendTime" label="提交时间" width="200"></el-table-column>
                <el-table-column prop="msgSignature" label="短信签名" width="120"></el-table-column>
                <el-table-column prop="msgContent" label="短信内容" :formatter="messContent"></el-table-column>
                <el-table-column prop="msgType" label="发送类型" :formatter="dateFormat" width="80"></el-table-column>
                <el-table-column
                  prop="msgSendStatus"
                  label="发送状态"
                  :formatter="sendStatus"
                  width="80"
                ></el-table-column>
                <el-table-column
                  prop="msgDeliveryStatus"
                  label="接收状态"
                  :formatter="deliveryStatus"
                  width="80"
                ></el-table-column>
                <el-table-column prop="msgFee" label="计费" width="60"></el-table-column>
                <el-table-column label="操作" width="100">
                  <template slot-scope="scope">
                    <el-button type="primary" size="small" @click="check(scope.row)">查看</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="block" v-if="total>10">
              <el-pagination
                background
                @current-change="handleCurrentChange"
                layout="prev, pager, next"
                :page-size="pagesize"
                :current-page="currentPage"
                :total="total"
              ></el-pagination>
            </div>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { getCookie } from "./until/index";
function init() {
  this.$ajax
    .get(
      "getUserMessageList.ashx?userId=" +
        getCookie("userid") +
        "&token=" +
        getCookie("token") +
        "&phoneNumber=" +
        this.iphone +
        "&sendTime=" +
        this.time +
        "&msgSendStatus=" +
        this.msgSendStatus +
        "&msgType=" +
        this.msgType +
        "&pi=" +
        this.currentPage +
        "&ps=" +
        this.pagesize
    )
    .then(res => {
      if (res.data.code === "200") {
        var data = res.data.data.auditList;

        this.tableData = data;
        this.total = Number(res.data.data.rowsCount);
      } else {
        this.$message.error(res.data.msg + "请退出后重新登录");
      }
    })
    .catch(error => {
      console.log(error);
    });
}
export default {
  data() {
    return {
      currentPage: 1, //初始页
      pagesize: 10,
      total: 0,
      time: "",
      value1: "",
      value2: "",
      msgSendStatus: "-1",
      msgType: "",
      options1: [
        {
          value: "待审核"
        },
        {
          value: "发送中"
        },
        {
          value: "已发送"
        },
        {
          value: "已取消"
        },
        {
          value: "被驳回"
        }
      ],
      options2: [
        {
          value: "短信"
        },
        {
          value: "闪信"
        }
      ],
      iphone: "",
      tableData: [],
      multipleSelection: []
    };
  },

  created() {
    init.call(this);
  },
  methods: {
    // 二次处理发送类型
    dateFormat(row, column) {
      var date = row[column.property];
      if (date == "DX") {
        return "短信";
      } else if (date == "SX") {
        return "闪信";
      }
    },
    // 二次处理发送状态
    sendStatus(row, column) {
      var date = row[column.property];
      if (date == "1") {
        return "待审核";
      } else if (date == "2") {
        return "发送中";
      } else if (date == "3") {
        return "已发送";
      } else if (date == "4") {
        return "已取消";
      } else if (date == "5") {
        return "被驳回";
      }
    },
    // 二次处理接收状态
    deliveryStatus(row, column) {
      var date = row[column.property];
      switch (date) {
        case "1":
          return "成功接收";
          break;
        case "2":
          return "接收失败";
          break;
        case "3":
          return "暂未返回";
          break;
        default:
          break;
      }
    },
    // 二次处理短信过长
    messContent(row, column) {
      var date = row[column.property];
      if (date.length > 40) {
        date = date.substr(0, 40) + "...";
      }
      return date;
    },
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage;
      init.call(this);
    },

    check(row) {
      this.$alert(row.msgContent, "短信内容");
    },
    getTime(e) {
      if (e) {
        var time = e;
        var sendTime =
          time.toLocaleDateString().replace(/\//g, "-") +
          " " +
          time.toTimeString().substr(0, 8);
        this.time = sendTime;
      }
    },
    change1(e) {
      this.value1 = e;
      switch (e) {
        case "待审核":
          this.msgSendStatus = "1";
          break;
        case "发送中":
          this.msgSendStatus = "2";
          break;
        case "已发送":
          this.msgSendStatus = "3";
          break;
        case "已取消":
          this.msgSendStatus = "4";
          break;
        case "被驳回":
          this.msgSendStatus = "5";
          break;
        default:
          break;
      }
    },
    change2(e) {
      this.value2 = e;

      switch (e) {
        case "短信":
          this.msgType = "DX";
          break;
        case "闪信":
          this.msgType = "SX";
          break;
        default:
          break;
      }
    },
    search() {
      init.call(this);
    }
  }
};
</script>
<style scoped>
.index {
  overflow: hidden;
}
.el-header {
  background-color: #3a4759;
  color: #fff;
}
.el-aside {
  background-color: #485668;
  color: #333;
  text-align: center;
  line-height: 200px;
  overflow: hidden;
}
.el-main {
  background-color: #f0eff5;
  color: #333;
  text-align: center;
  height: 100%;
}
.audit {
  min-height: 100vh;
}
.block {
  margin-top: 20px;
}
table tr th {
  background: #f5f7fa;
  text-align: center;
}
.search {
  width: 100%;
  background: #fff;
  padding: 20px;
  display: flex;
  box-sizing: border-box;
  margin-bottom: 20px;
}
.title {
  font-size: 30px;
  font-weight: 500;
  margin-bottom: 20px;
}
.item {
  float: left;
  text-align: left;
  margin-right: 10px;
}
.item label {
  line-height: 35px;
}
.el-input {
  width: 150px;
}
.searchs {
  float: right;
  margin-left: 20px;
}
</style>
  